﻿using AutoMapper;
using B.Auth.APi.Application.Command.Leaves;
using B.Auth.Domain.Entity;
using B.Auth.Domain.Repository;
using B.Auth.Enum;
using MediatR;

namespace B.Auth.APi.Application.CommandHand.Leaves
{
    public class LeaveDelCommandHand : IRequestHandler<LeaveDelCommand, ApiResult<int>>
    {

        private readonly IBaseRepository<LeaveModel> _leave;
        private readonly IMapper mapper;

        public LeaveDelCommandHand(IBaseRepository<LeaveModel> leave, IMapper mapper)
        {
            _leave = leave;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(LeaveDelCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<int>();

            var Leave = new LeaveModel();
            var leaves = mapper.Map<LeaveModel>(request);
            leaves.Del = 1;
            _leave.Update(leaves);
            result.Code = ApiEnum.ok;
            result.Message = "删除成功";
            result.data = 1;

            return Task.FromResult(result);
        }
    }
}
